/*
 * CGemType.java
 *
 * Copyright (c) 2009 Giles Millward (Manigra). All rights reserved.
 *
 * This file is part of JRogueDPS.
 *
 * JRogueDPS is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * JRogueDPS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with JRogueDPS.  If not, see <http://www.gnu.org/licenses/>.
 */

package geardatabase;

import javax.swing.ImageIcon;

/**
 *
 * @author gmillward
 */
public class CGemType {
    public enum GemType {META, RED, BLUE, GREEN, PURPLE, YELLOW, ORANGE, PRISMATIC, UNKNOWN};

    static ImageIcon m_metaGem;
    static ImageIcon m_redGem;
    static ImageIcon m_blueGem;
    static ImageIcon m_greenGem;
    static ImageIcon m_purpleGem;
    static ImageIcon m_yellowGem;
    static ImageIcon m_orangeGem;
    static ImageIcon m_prismaticGem;
    static ImageIcon m_unknownGem;
    static ImageIcon m_grayBall;

    static public void initGemImages(ClassLoader p_cl)
    {
        m_metaGem = new ImageIcon(p_cl.getResource("geardatabase/images/meta_gem.png"));
        m_redGem = new ImageIcon(p_cl.getResource("geardatabase/images/red_gem.png"));
        m_blueGem = new ImageIcon(p_cl.getResource("geardatabase/images/blue_gem.png"));
        m_greenGem = new ImageIcon(p_cl.getResource("geardatabase/images/green_gem.png"));
        m_purpleGem = new ImageIcon(p_cl.getResource("geardatabase/images/purple_gem.png"));
        m_yellowGem = new ImageIcon(p_cl.getResource("geardatabase/images/yellow_gem.png"));
        m_orangeGem = new ImageIcon(p_cl.getResource("geardatabase/images/orange_gem.png"));
        m_prismaticGem = new ImageIcon(p_cl.getResource("geardatabase/images/prismatic_gem.png"));
        m_unknownGem = new ImageIcon(p_cl.getResource("geardatabase/images/unknown_gem.png"));
        m_grayBall = new ImageIcon(p_cl.getResource("geardatabase/images/gray_ball.png"));
    }

    static public ImageIcon getGrayBall()
    {
        return m_grayBall;
    }
    
    static public ImageIcon getGemImage(GemType p_gemType)
    {
        if (p_gemType == GemType.META)
        {
            return m_metaGem;
        } else if (p_gemType == GemType.RED)
        {
            return m_redGem;
        } else if (p_gemType == GemType.BLUE)
        {
            return m_blueGem;
        } else if (p_gemType == GemType.GREEN)
        {
            return m_greenGem;
        } else if (p_gemType == GemType.PURPLE)
        {
            return m_purpleGem;
        } else if (p_gemType == GemType.YELLOW)
        {
            return m_yellowGem;
        } else if (p_gemType == GemType.PRISMATIC)
        {
            return m_prismaticGem;
        } else if (p_gemType == GemType.ORANGE)
        {
            return m_orangeGem;
        }

        return m_unknownGem;
    }

    static public String getGemName(GemType p_gemType)
    {
        if (p_gemType == GemType.META)
        {
            return "Meta";
        } else if (p_gemType == GemType.RED)
        {
            return "Red";
        } else if (p_gemType == GemType.BLUE)
        {
            return "Blue";
        } else if (p_gemType == GemType.GREEN)
        {
            return "Green";
        } else if (p_gemType == GemType.PURPLE)
        {
            return "Purple";
        } else if (p_gemType == GemType.YELLOW)
        {
            return "Yellow";
        } else if (p_gemType == GemType.PRISMATIC)
        {
            return "Prismatic";
        } else if (p_gemType == GemType.ORANGE)
        {
            return "Orange";
        }

        return "Unknown";
    }

    static public GemType getGemType(String p_gemName)
    {
        if (p_gemName.toLowerCase().equals("meta"))
        {
            return GemType.META;
        } else if (p_gemName.toLowerCase().equals("red"))
        {
            return GemType.RED;
        } else if (p_gemName.toLowerCase().equals("blue"))
        {
            return GemType.BLUE;
        } else if (p_gemName.toLowerCase().equals("green"))
        {
            return GemType.GREEN;
        } else if (p_gemName.toLowerCase().equals("purple"))
        {
            return GemType.PURPLE;
        } else if (p_gemName.toLowerCase().equals("yellow"))
        {
            return GemType.YELLOW;
        } else if (p_gemName.toLowerCase().equals("prismatic"))
        {
            return GemType.PRISMATIC;
        } else if (p_gemName.toLowerCase().equals("orange"))
        {
            return GemType.ORANGE;
        }

        return GemType.UNKNOWN;
    }

    public static boolean matchGem(GemType p_socketColor, GemType p_gemColor)
    {
        if (p_socketColor == GemType.META && p_gemColor == GemType.META)
        {
            return true;
        }

        
        if (p_gemColor == GemType.PRISMATIC && p_socketColor != GemType.META)
        {
            return true;
        }

        if (p_socketColor == GemType.RED)
        {
            if (p_gemColor == GemType.RED ||
                    p_gemColor == GemType.ORANGE ||
                    p_gemColor == GemType.PURPLE)
            {
                return true;
            }
        } else if (p_socketColor == GemType.BLUE)
        {
            if (p_gemColor == GemType.BLUE ||
                    p_gemColor == GemType.GREEN ||
                    p_gemColor == GemType.PURPLE)
            {
                return true;
            }
         } else if (p_socketColor == GemType.YELLOW)
        {
            if (p_gemColor == GemType.YELLOW ||
                    p_gemColor == GemType.GREEN ||
                    p_gemColor == GemType.ORANGE)
            {
                return true;
            }
        }

        return false;
    }

    // Used for meta gem requirements to see if a gem is compatible
    static public boolean metaGemCompatible(GemType p_primaryGem, GemType p_targetGem)
    {
        if (p_primaryGem == GemType.RED)
        {
            if (p_targetGem == GemType.RED ||
                p_targetGem == GemType.ORANGE ||
                p_targetGem == GemType.PRISMATIC ||
                p_targetGem == GemType.PURPLE)
            {
                return true;
            }
        } else if (p_primaryGem == GemType.BLUE)
        {
            if (p_targetGem == GemType.BLUE ||
                p_targetGem == GemType.PURPLE ||
                p_targetGem == GemType.PRISMATIC ||
                p_targetGem == GemType.GREEN)
            {
                return true;
            }
        } else if (p_primaryGem == GemType.YELLOW)
        {
            if (p_targetGem == GemType.YELLOW ||
                p_targetGem == GemType.ORANGE ||
                p_targetGem == GemType.PRISMATIC ||
                p_targetGem == GemType.GREEN)
            {
                return true;
            }
        }

        return false;
    }
}
